export interface IProduct {
  productId: string;
  productName: string;
  price: number;
  unit: string;
}

const demoProduct: IProduct = {
  productId: '123',
  productName: '吉利嘉际',
  unit: '辆',
  price: 15880,
};

/**
 * 根据产品标识获取产品信息
 */
export function getProductById(productId: string): Promise<IProduct> {
  // console.log('query product', productId);
  return new Promise(resolve => {
    setTimeout(() => {
      const p = { ...demoProduct };
      p.price = Math.ceil(Math.random() * 10000) + 50000;
      resolve(p);
    }, 500);
  });
}

/**
 *
 * @param price 根据目标价格查询相似价格的产品清单
 */
export function getSimilarPriceProduct(price: number) {
  console.log('getSimilarPriceProduct', price);
  return new Promise(resolve => {
    setTimeout(() => {
      resolve([
        { productName: '大通G50', price: 140000 },
        { productName: '广汽GM6', price: 135000 },
      ]);
    }, 500);
  });
}
